home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performPolySubdivide.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.0 KB  |  231 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  4 April 1997
  22. //
  23. //  Procedure Name:
  24. //      performPolySubdivide
  25. //
  26. //  Description:
  27. //        subdivide the selected polygon facets or edges
  28. //         
  29. //  Input Arguments:
  30. //        $option : Whether to set the options to default values.
  31. //  Return Value:
  32. //        command string iff $option==2
  33. //
  34.  
  35. proc setOptionVars (string $comp, int $forceFactorySettings)
  36. {               
  37.      if ($forceFactorySettings || !`optionVar -exists ("polySubdSubd" + $comp)`)
  38.         optionVar -intValue ("polySubdSubd" + $comp) 1;
  39.     if ($comp =="f") {
  40.         if ($forceFactorySettings || !`optionVar -exists ("polySubdFacetMode" + $comp)`)
  41.             optionVar -intValue ("polySubdFacetMode" + $comp) 1;
  42.     } else {
  43.         if ($forceFactorySettings || !`optionVar -exists ("polySubdLen" + $comp)`)
  44.             optionVar -floatValue ("polySubdLen" + $comp) 0;
  45.         if ($forceFactorySettings || !`optionVar -exists ("polySubdWS" + $comp)`)
  46.             optionVar -intValue ("polySubdWS" + $comp) 0;
  47.     }
  48. }
  49.  
  50. global proc performPolySubdivideSetup (string $comp, string $parent, int $forceFactorySettings)
  51. {
  52.     setOptionVars($comp, $forceFactorySettings);
  53.     setParent $parent;
  54.     
  55.     int $ival = `optionVar -query ("polySubdSubd" + $comp)`;
  56.     intSliderGrp -edit -value $ival polySubdSubd;
  57.     if ($comp =="f") {
  58.         int $ival = `optionVar -query ("polySubdFacetMode" + $comp)`;
  59.          optionMenuGrp -edit -sl $ival polySubdFacetMode;
  60.     } else {
  61.         float $val = `optionVar -query ("polySubdLen" + $comp)`;
  62.         floatSliderGrp -edit -value $val polySubdLen;
  63.         int $ival = `optionVar -query ("polySubdWS" + $comp)`;
  64.          checkBoxGrp -edit -value1 $ival polySubdWS;
  65.     }
  66. }
  67.  
  68. global proc performPolySubdivideCallback (string $comp, string $parent, int $doIt)
  69. {
  70.     setParent $parent;
  71.     
  72.     optionVar -intValue ("polySubdSubd" + $comp) 
  73.         `intSliderGrp -query -value polySubdSubd`;
  74.     if ($comp =="f")
  75.         optionVar -intValue ("polySubdFacetMode" + $comp) 
  76.             `optionMenuGrp -query -sl polySubdFacetMode`;
  77.     else {
  78.         optionVar -floatValue ("polySubdLen" + $comp) 
  79.             `floatSliderGrp -query -value polySubdLen`;
  80.         optionVar -intValue ("polySubdWS" + $comp) 
  81.             `checkBoxGrp -query -value1 polySubdWS`;
  82.     }
  83.     if ($doIt) {
  84.         performPolySubdivide $comp 0;
  85.         string $tmpCmd = "performPolySubdivide \"" + $comp + "\" 0";
  86.         string $tmpLabel = "PolySubdivideEdge";
  87.         if ($comp =="f") $tmpLabel = "PolySubdivideFacet";
  88.         addToRecentCommandQueue $tmpCmd $tmpLabel;
  89.     }
  90. }
  91.  
  92. proc polySubdivideOptions (string $comp)
  93. {
  94.     string $commandName = "performPolySubdivide";
  95.     string $callback = ($commandName + "Callback " + $comp);
  96.     string $setup = ($commandName + "Setup " + $comp);
  97.        
  98.     string $layout = getOptionBox();
  99.     setParent $layout;
  100.     setUITemplate -pushTemplate DefaultTemplate;
  101.     waitCursor -state 1;
  102.     
  103.     string $parent = `columnLayout -adjustableColumn 1`;
  104.  
  105.     intSliderGrp -label "Subdivision Levels" -min 1 -max 4 polySubdSubd;
  106.     
  107.     if ($comp == "f")
  108.     {
  109.         optionMenuGrp  -l "Mode" polySubdFacetMode;
  110.             menuItem -l "quads" SubdFacetQuadsMenuItem;
  111.             menuItem -l "triangles" SubdFacetTrgsMenuItem;
  112.         setParent -m ..;
  113.         optionMenuGrp -e -sl 1 polySubdFacetMode;
  114.     }
  115.     else {
  116.         floatSliderGrp -label "Minimum Length" -min 0 -max 10 -fmn 0 -fmx 1000 polySubdLen;
  117.         checkBoxGrp -label1 "Worldspace" polySubdWS;
  118.     }
  119.     waitCursor -state 0;
  120.     setUITemplate -popTemplate;
  121.        
  122.     string $applyBtn = getOptionBoxApplyBtn();
  123.     button -edit -label "Subdivide"
  124.            -command ($callback + " " + $parent + " " + 1)
  125.         $applyBtn;
  126.     string $saveBtn = getOptionBoxSaveBtn();
  127.     button -edit 
  128.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  129.         $saveBtn;
  130.     string $resetBtn = getOptionBoxResetBtn();
  131.     button -edit 
  132.         -command ($setup + " " + $parent + " " + 1)
  133.         $resetBtn;
  134.  
  135.     string $lbl="Edge"; string $obj="Edge";
  136.     if ($comp == "f") { $lbl="Face"; $obj="Facet"; }
  137.  
  138.     setOptionBoxTitle("Polygon Subdivide " + $lbl + " Options");
  139.  
  140.     //    Customize the 'Help' menu item text.
  141.     //
  142.     setOptionBoxHelpTag( "EditPolygonsSubdivide" );
  143.  
  144.     eval (($setup + " " + $parent + " " + 0));
  145.     scriptJob -protected
  146.         -parent $parent 
  147.         -event "SelectTypeChanged" "evalDeferred \"performPolySubdivide \\\"\\\" 1\"";
  148.  
  149.     showOptionBox();
  150. }
  151.  
  152. global proc string performPolySubdivide (string $comp, int $option)
  153. {
  154.     string $cmd="";
  155.     string $obj="";
  156.     if ($comp == "") {
  157.         // If no comp is specified, use the selection list to decide on E/F
  158.         if (size(`filterExpand -sm 34`) != 0) { $comp="f"; $obj="Facet"; }
  159.         else if (size(`filterExpand -sm 32`) != 0) { $comp="e"; $obj="Edge"; }
  160.         else {
  161.         // If nothing is selected, check which is about to be selected!!
  162.             if (`selectMode -q -object`) { // Object Selection Mode
  163.                 // Check for RMB component selection 
  164.                 if (`selectType -q -ocm -facet`) { $comp="f"; $obj="Facet"; }
  165.                 else if (`selectType -q -ocm -edge`) { $comp="e"; $obj="Edge"; }
  166.             } else {                    // Component Selection Mode
  167.                 if (`selectType -q -facet`) { $comp="f"; $obj="Facet"; }
  168.                 else if (`selectType -q -edge`) { $comp="e"; $obj="Edge"; }
  169.             }
  170.             if ($comp == "") {            // If still unresolvable, give up!!
  171.                 if ($option == 1) { $comp="f"; $obj="Facet"; } 
  172.                    else if ($option < 2) {
  173.                     warning "Polygons edges or faces must be selected to subdivide them.";
  174.                     return "";
  175.                 }
  176.             }
  177.         }
  178.     } else {
  179.         if ($comp == "f") $obj="Facet";
  180.         else if ($comp == "e") $obj="Edge";
  181.         else {
  182.             if ($option < 2) {
  183.                 warning "Only Polygon edges and faces can be subdivided.";
  184.                 return "";
  185.             }
  186.         }
  187.     }
  188.     string $sel[];
  189.     string $res[];
  190.     switch ($option) {
  191.     case 0:
  192.         setOptionVars($comp, false);
  193.         if ($comp == "f") {
  194.             int $ival = `optionVar -query polySubdSubdf`;
  195.             int $iv2 = `optionVar -query polySubdFacetModef` -1;
  196.             $cmd=("polySubdivideFacet -dv " + $ival + " -m " + $iv2);
  197.         } else {
  198.             int $ival = `optionVar -query polySubdSubde`;
  199.             float $val =`optionVar -query polySubdLene`;
  200.             int $ws = `optionVar -query polySubdWSe`;
  201.             $cmd=("polySubdivideEdge -ws " + $ws + " -s " + $val + " -dv " + $ival);
  202.         }
  203.         polyPerformAction $cmd $comp 0;
  204.         break;
  205.     case 1: polySubdivideOptions $comp; break;
  206.     case 2:
  207. /*
  208.         setOptionVars($comp, false);
  209.         // note that by 'freezing' the parameters, we now have to stick
  210.         // the shelf item to either 'subdivide edges' or 'subdivide facets'
  211.         // hence the command losses a bit of functionality: instead of
  212.         // smartly applying to either edges or facets, it will apply
  213.         // to only one of those categories.        
  214.         if ($comp == "e") {
  215.             int $ival = `optionVar -query polySubdSubde`;
  216.             float $val =`optionVar -query polySubdLene`;
  217.             int $ws = `optionVar -query polySubdWSe`;
  218.             $cmd=("polySubdivideEdge -ws " + $ws + " -s " + $val + " -dv " + $ival);
  219.         } else if ($comp == "f") {
  220.             int $ival = `optionVar -query polySubdSubdf`;
  221.             int $iv2 = `optionVar -query polySubdFacetModef` -1;
  222.             $cmd=("polySubdivideFacet -dv " + $ival + " -m " + $iv2);
  223.         } else $cmd="performPolySubdivide \"\" 0";
  224.         if ($comp != "")
  225.             $cmd=("polyPerformAction \""+ $cmd + "\" " + $comp + " 0");
  226. */
  227.         $cmd="performPolySubdivide \"\" 0";
  228.     }
  229.     return $cmd;
  230. }
  231.